//
//  DYTabBarButton.m
//
//  Created by 丁益 on 15/6/21.
//  Copyright (c) 2015年 丁益. All rights reserved.
//

#import "DYTabBarButton.h"
#import "CLDeviceIOS.h"
@implementation DYTabBarButton

#define BtnDefaultImageW 30

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        //设置图标居中显示
        self.imageView.contentMode = UIViewContentModeCenter;
        
        //设置文字右对齐
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        
        [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        /*if (sWidth > 320) {
            self.titleLabel.font = [UIFont boldSystemFontOfSize:10];
        } else {
            self.titleLabel.font = [UIFont boldSystemFontOfSize:6];
        }*/
//        self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;  //多行文字显示
        self.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;  //"abcd..."
        //设置高亮时候不要调整图标为灰色
        self.adjustsImageWhenHighlighted = NO;;
    }
    
    return self;
}

/**
 *     设置图标frame
 */
-(CGRect)imageRectForContentRect:(CGRect)contentRect
{
    
    CGFloat imageY = 0;
    CGFloat imageW =  BtnDefaultImageW;
    CGFloat imageH = BtnDefaultImageW;
    CGFloat imageX = (self.frame.size.width-BtnDefaultImageW)/2;
    return CGRectMake(imageX, imageY, imageW, imageH);
}
/**
 *     设置内部文字的frame
 */
-(CGRect)titleRectForContentRect:(CGRect)contentRect
{
    
    CGFloat titleX = 0;
    
    
    //    CGFloat titleX = BtnDefaultImageW+5;
    CGFloat titleY = BtnDefaultImageW-3;
    CGFloat titleW = self.frame.size.width;
    CGFloat titleH = self.frame.size.height - BtnDefaultImageW;
    return CGRectMake(titleX, titleY, titleW, titleH);
}


@end
